package com.ruoyi.common.core.json;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.JSONWriter;

public class FastjsonUtils {
    /**
     * 对象转 JSON 字符串
     */
    public static String toJson(Object obj) {
        return JSON.toJSONString(obj, JSONWriter.Feature.WriteNulls);
    }

    /**
     * JSON 字符串转对象
     */
    public static <T> T fromJson(String json, Class<T> clazz) {
        return JSON.parseObject(json, clazz, JSONReader.Feature.SupportAutoType);
    }
}
